package com.enumdemo;

import java.util.Random;

/**
 * 更加通用的Generator
 * 
 * @author Administrator
 * 
 */

enum Activity {
	SLAPPY, SPANKY, PUNCHY, SILLY, BOUNCY, NUTTY, BOB;
}

public class ImplementDemo2 {

	private static Random rand = new Random(47);

	// 以Class<T>作为参数的话，可以利用getEnumConstants()获取enum实例数组
	public static <T extends Enum<T>> T random(Class<T> ec) {
		return random(ec.getEnumConstants());
	}

	public static <T> T random(T[] values) {
		return values[rand.nextInt(values.length)];
	}

	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			System.out.print(ImplementDemo2.random(Activity.class) + " ");
		}
	}

}
